//
//  FirstPageRankingRequest.m
//  BSLCar
//
//  Created by 梁毅 on 15/5/25.
//  Copyright (c) 2015年 lyz. All rights reserved.
//

#import "FirstPageRankingRequest.h"
//#import "FPRankingViewController.h"

@implementation FirstPageRankingRequest
- (NSArray *)getParserResult:(NSString *)typeID
{
    NSMutableArray *dataArray = [NSMutableArray array];

    self.typeId = @"1";
    NSNotificationCenter *center  = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(receivieData:) name:@"FPRanking" object:nil];
    NSString *string = @"http://baojia.qichecdn.com/priceapi3.9.2/services/hotcar/get?type=";
    NSString *str = [NSString stringWithFormat:@"%@%@", string, typeID];
    
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];
    NSError *error = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
    if (!error) {
        //字典里字典，字典里数组，数组里字典，字典里数组，数组里字典
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        NSDictionary *dic1 = [dic objectForKey:@"result"];
        
        NSArray *array = [dic1 objectForKey:@"hotcarlist"];
        
        for (NSDictionary *dic2 in array) {
            
            NSMutableArray *array3 = [NSMutableArray array];
            [array3 addObject:[dic2 objectForKey:@"name"]];
            
            NSArray *array1 = [dic2 objectForKey:@"serieslist"];
            
            
            for (NSDictionary *dic5 in array1) {
                FPRankingModel *model = [FPRankingModel getFPRankingModel];
                
                model.price = [dic5 objectForKey:@"price"];
                
                model.imgurl = [dic5 objectForKey:@"imgurl"];
                model.id1 = [[dic5 objectForKey:@"id"] integerValue];
                
                model.ordercount = [[dic5 objectForKey:@"ordercount"] stringValue];
                
                model.name1 = [dic5 objectForKey:@"name"];
                
                [array3 addObject:model];
            }
            
            [dataArray addObject:array3];
        }
        
    }
    return dataArray;

}
- (void)receivieData:(NSNotification *)sender {
    self.typeId = [sender object];
}
@end
